<?php
class Controller_Base
{
	const BASE_PAGE_TITLE = 'HackerU';
	
	protected $actionName;
	protected $controllerName;
	
	protected $view;
	protected $model;
	protected $request;
	
	protected $disabledView = false;
	
	public function __construct($actionName)
	{
		$this->controllerName = str_replace('Controller_', '', get_class($this));
		$this->actionName = (string)$actionName;
		$this->view = new HackerU_View();
		
		$this->request = HackerU_Http::getInstance();
	}
	
	
	public function preDispatch()
	{
		
	}
	
	public function postDispatch()
	{
		if(!$this->disabledView){
			$this->view->actionName = $this->actionName;
			$this->view->controllerName = $this->controllerName;
			$this->view->render();
		}
	}
	
	/**
	 * 
	 * call to new action
	 * @param array $data assoc(ctrl act etc)
	 */
	public function _forward(array $data)
	{
		$this->actionName = isset($data['act']) ? $data['act'] : $this->actionName;
		$actionName = $this->actionName;
		$this->$actionName();
	}
	
	public function dispatch()
	{
		$actionName = $this->actionName;
		$this->preDispatch();
		$this->$actionName();
		$this->postDispatch();
	}
	
	/**
	 * 
	 * redirect location
	 * @param array $data assoc(ctrl act etc)
	 */
	public function redirect(array $data)
	{
		$this->disabledView = true;
		$actionName = isset($data['act']) ? $data['act'] : $this->actionName;
		$controllerName = isset($data['ctrl']) ? $data['ctrl'] : $this->controllerName;
		$url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
		header("Location: $url?a=$controllerName/$actionName");
		
	}
	
	public function index()
	{
		
	}
}